# -*- coding: utf-8 -*-
# @Time : 2021/9/17 20:52
# @Author : jiangping
# @Email : jp@gmail.com
# @File : sortgoods_page.py
# @Project : mryx_test
"""分类商品页面类"""
from page.base_page import BasePage
from appium.webdriver.common.mobileby import MobileBy as By
class SortGoods(BasePage):
    """定义定位器"""
    goods_locator = (By.XPATH, '//androidx.recyclerview.widget.RecyclerView'
                               '[@resource-id=\"cn.missfresh.application:id/recycler_view\"]'
                               '/android.widget.RelativeLayout[1]')  # 第一个商品
    add1_locator = (By.XPATH, '//androidx.recyclerview.widget.'
                              'RecyclerView[@resource-id=\"cn.missfresh.'
                              'application:id/recycler_view\"]/android.widget.'
                              'RelativeLayout[1]/android.widget.LinearLayout[1]/android.'
                              'widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.'
                              'widget.FrameLayout[1]/android.widget.ImageView[1]')  # 第一个商品的加号
    settlement_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("去结算(1)")')  # 去结算按钮
    cart_locator = (By.ID, 'cn.missfresh.application:id/iv_cart')  # 购物车图标
    determine_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("确定")')  # 弹窗的确定按钮
    # 购物车详情页
    del_locator = (By.XPATH, '//android.view.View[@content-desc=\"删除\"]')  # 删除
    price_locator = (By.ID, 'cn.missfresh.application:id/tv_price')  # 价格

    def click_firstgoods(self):
        """点击第一个商品"""
        self.driver.find_element(*self.goods_locator).click()

    def add_goods(self):
        """添加商品到购物车"""
        self.driver.find_element(*self.add1_locator).click()

    def click_cart(self):
        """点击购物车"""
        self.driver.find_element(*self.cart_locator).click()

    def click_determine(self):
        """点击弹窗的确定按钮"""
        self.driver.find_element(*self.determine_locator).click()

    def click_delete(self):
        """点击删除"""
        self.driver.find_element(*self.del_locator).click()

    def click_price(self):
        """点击价格"""
        self.driver.find_element(*self.price_locator).click()
